package com.nexgo.payment.trans.setting.othersfunc;

import android.os.Bundle;
import android.view.Gravity;

import com.nexgo.payment.R;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.fragment.TextDialogFragment;
import com.nexgo.payment.trans.setting.SaveParameterContract;
import com.nexgo.payment.trans.setting.SaveParameterPresenter;
import com.nexgo.payment.ui.ListMenuActivity;
import com.nexgo.payment.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 清除菜单界面
 *
 * @author 谭忠扬-YuriTam
 * @time 2017年8月15日
 */
public class SetupClearTransRecordActivity extends ListMenuActivity implements SaveParameterContract.View{
    private static final String TAG = SetupClearTransRecordActivity.class.getSimpleName();
    private List<Integer> mItemList;
    private SaveParameterContract.Presenter mPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        new SaveParameterPresenter(this, Repository.getInstance());
    }

    private void initView() {
        mItemList = new ArrayList<>();
        mItemList.add(R.string.clear_trans_history);
        mItemList.add(R.string.clear_reverse_trans);
        for (Integer i : mItemList) {
            addItem(i);
        }
    }

    @Override
    protected String getActivityTitle() {
        return getString(R.string.clear_menu);
    }

    @Override
    protected void onItemClick(int position) {
        int item = mItemList.get(position);
        clearDataByType(item);
    }

    private void clearDataByType(int resId) {
        TextDialogFragment dialogFragment = TextDialogFragment.newInstance();
        dialogFragment.setDialogType(TextDialogFragment.DIALOG_TYPE_WARNING);
        dialogFragment.setTitleText(getString(R.string.kindly_tip));
        dialogFragment.setContentText(getString(resId), Gravity.CENTER);
        dialogFragment.setPositionText(getString(R.string.confirm));
        dialogFragment.setNegativeText(getString(R.string.cancel));
        dialogFragment.setDialogListener(new TextDialogFragment.OnDialogListener() {
            @Override
            public void onCancel() {
            }

            @Override
            public void onConfirm() {
                switch (resId) {
                    case R.string.clear_trans_history://清除流水数据
                        mPresenter.clearVoucherRecord();
                        break;
                    case R.string.clear_reverse_trans://清除冲正数据
                        mPresenter.clearReversalRecord();
                        break;
                    default:
                        break;
                }
                ToastUtils.showToast(getString(R.string.clear_data_success));
            }
        });
        dialogFragment.show(getSupportFragmentManager(), null);
    }

    @Override
    public void setPresenter(SaveParameterContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public void showDetail() {

    }

    @Override
    public void showTip(String tip) {

    }

    @Override
    public void showInputSecurityPassword() {

    }

    @Override
    public void showSaveParamSuccessfully() {

    }

    @Override
    public void showNeedSettle() {

    }
}
